package com.shuai.api_platform.handler;

import com.shuai.api_platform.manager.RandomNumManager_bak2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//@Configuration
public class AuthenticationInterceptor implements HandlerInterceptor {


    /**
     * 鉴权 -- 随机数管理器
     */
    @Autowired
    private RandomNumManager_bak2 randomNumManagerBak2;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        String apiKey = request.getHeader(AuthenticationConstant.API_KEY);
//        String random = request.getHeader(AuthenticationConstant.RANDOM);
//        String timestamp = request.getHeader(AuthenticationConstant.TIMESTAMP);
//        if (StringUtils.isAnyBlank(apiKey, random, timestamp)) {
//            throw new BusinessException(ErrorCode.NO_AUTH_ERROR);
//        }
//
//        ServletInputStream inputStream = request.getInputStream();
//        ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
//        APIMessage message = (APIMessage) objectInputStream.readObject();
//        //TODO: 鉴权处理
//
//        // 首先，验证APIkey是否存在，如果存在，从数据库中获取API-SECRET信息
//
//
//        // 首先，验证随机数是否已经出现过
//        if (randomNumManager.hasRandomVal(apiKey, Long.parseLong(random))) {
//
//        }
        return false;
    }
}
